package com.ts.main.mini.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ts.main.mini.dto.ProductSearchDto;
import com.ts.main.mini.dto.ProductSearchPageDto;
import com.ts.main.mini.entity.ProductEntity;
import com.ts.main.mini.exception.RPage;
import com.ts.main.mini.mapper.ProductMapper;
import com.ts.main.mini.vo.ProductDetailsToCartVo;
import com.ts.main.mini.vo.ProductVariantVo;
import com.ts.main.mini.vo.ProductVo;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lk
 * @description 针对表【t_product(商品表)】的数据库操作Service实现
 * @createDate 2025-05-16 15:11:54
 */
@AllArgsConstructor
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductEntity> {

    private final ProductVariantServiceImpl productVariantServiceImpl;


    public RPage<List<ProductVo>> getProductPage(ProductSearchPageDto dto) {
        Page<Object> page = PageHelper.startPage(dto.getPage(), dto.getLimit());
        List<ProductVo> list = baseMapper.getProductPage(dto);
        return RPage.ok(list, dto.getPage(), dto.getLimit(), page.getTotal());
    }

    public List<ProductVo> getProductList(ProductSearchDto dto) {
        return baseMapper.getProductList(dto);
    }

    public ProductVo getProductDetails(Integer productId) {
        return baseMapper.getProductDetails(productId);
    }

    public ProductDetailsToCartVo getProductDetailsToCart(Integer productId) {
        return  baseMapper.getProductDetailsToCart(productId);
    }


    public ProductVariantVo getProductCombination(Integer productId, String optionCombination) {
        return productVariantServiceImpl.getProductCombination(productId, optionCombination);
//        if(ObjectUtil.isEmpty(productCombination) || productCombination.getStatus().equals(Boolean.FALSE)) {
//            throw new CommonException("该组合无效");
//        }
//        return productCombination;
    }
}




